/*
 * FolderDescription.hpp
 *
 *  Created on: 04.05.2011
 *      Author: niea
 */

#ifndef FOLDERDESCRIPTION_HPP_
#define FOLDERDESCRIPTION_HPP_

#include <string>
#include <vector>
#include "../../rapidxml-1.13/rapidxml.hpp"
#include "../../rapidxml-1.13/rapidxml_print.hpp"

namespace efs
{

enum FileType
{
	FileType_file,
	FileType_folder
};

enum FileStatus
{
	FileStatus_stored,
	FileStatus_modified,
	FileStatus_deleted,
	FileStatus_conflict,
	FileStatus_out_of_scope
};

struct FileDescription
{
	std::string path;
	FileType file_type;
	FileStatus file_status;
	int size;

	FileDescription();
	void print() const;
	bool operator==(FileDescription const &fd) const;
};

class FolderDescription
{
public:
	FolderDescription();
	FolderDescription(std::string const &root_path);
	virtual ~FolderDescription();
	void setRootPath(std::string const &path);
	std::vector<FileDescription> const& getFolderDescription() const;
	void clear();
	bool scanFolder();
	void toXML(rapidxml::xml_document<> &xml, rapidxml::xml_node<> *root_node);
	void fromXML(rapidxml::xml_document<> &xml, rapidxml::xml_node<> *root_node);
	void print(std::vector<FileDescription> const &files) const;
	void print() const;
	void splitEntryList(std::vector<FileDescription> const& list,
			std::vector<std::string> &files,
			std::vector<std::string> &folders) const;
	void applyMyChanges(std::vector<FileDescription> const& changes_list);
	int itemsCount() const;

private:
	std::string m_root_path;
	bool m_first_start;
	bool m_first_announce;
	std::vector<FileDescription> m_files;

	void scanFolder(std::vector<FileDescription> &files,
			std::string const &root_path,
			std::string const &path) const;

	std::vector<FileDescription> compareNewVersion(std::vector<FileDescription> files_old,
			std::vector<FileDescription> files_new) const;
//TODO:
public:
	void compareExternal(std::vector<FileDescription> const &c_files_ext,
			std::vector<FileDescription> &get_list,
			std::vector<FileDescription> &remove_list,
			bool first_announce = false);

	bool isEqual(std::vector<FileDescription> files_1,
			std::vector<FileDescription> files_2);

	std::vector<FileDescription>::iterator getFileByPath(std::vector<FileDescription> &files_ext, std::string const &path);
};

}

#endif /* FOLDERDESCRIPTION_HPP_ */
